package hotciv.variants;

import java.util.*;

import hotciv.common.*;
import hotciv.framework.*;
import hotciv.strategies.WinnerStrategy;

public class EpsilonCivWinnerStrategy implements WinnerStrategy {

	@Override
	public Player getWinner(ModifiableGame game) {
		Map<Integer, Collection<Player>> wins = game.getWonAttacks();
		Map<Player, Integer> accumulatedWins = new HashMap<Player, Integer>();
		
		for(Integer year : wins.keySet()) { //iterate through all years in Collection
			Collection<Player> col = wins.get(year); //get the collection of the current year
			
			for(Player pl : col) { //iterate through the players in the year-collection
				Integer accWins = accumulatedWins.get(pl);
				if (accWins == null) accWins = 0;
				int plVal = accWins;
				int newVal = plVal+1;
				accumulatedWins.put(pl, newVal);
				if (newVal >= 3) return pl;
			}
		}
		
		return null;
	}

}
